package org.embedchat.server.live;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.apache.mina.common.IoSession;

import org.embedchat.entity.ChatRoom;
import org.embedchat.entity.User;

public class OnlineChatRoom {
	
	private ChatRoom room;
	private Map<IoSession, OnlineUser> usersMap = new HashMap<IoSession, OnlineUser>();

	public OnlineChatRoom(ChatRoom room) {
		this.room = room;
	}
	
	public void addUser(IoSession userSession, User user) {
		OnlineUser onlineUser = new OnlineUser(user);
		usersMap.put(userSession, onlineUser);
	}
	
	public void removeUser(IoSession session) {
		usersMap.remove(session);
	}

	public boolean isSessionPresent(IoSession session) {
		return usersMap.containsKey(session);
	}
	
	public boolean isUserPresent(User user) {
		return usersMap.containsValue(user);
	}
	
	public OnlineUser getUser(IoSession userSession) {
		return usersMap.get(userSession);
	}
	
	public ChatRoom getRoom() {
		return room;
	}
	
	public Collection<OnlineUser> getOnlineUsers() {
		return usersMap.values();
	}
	
	public Set<IoSession> getOnlineUsersSessions() {
		return usersMap.keySet();
	}
	
}
